<style lang="less">

</style>
<template>
    <div>
        <Drawer :closable="false" placement="right" v-model="drawerVisible" width="50%" :title="drawerTitle">
            <Row>
                <Col>
                <Card :shadow="false">
                    <Row>
                        <Form ref="form" :model="form" :label-width="90" style="position:relative">
                            <FormItem label="模块名称" prop="tagName">
                                <Input v-model="form.tagName" style="width:600px"/>
                            </FormItem>
                            <FormItem label="排序" prop="sortOrder">
                                <InputNumber v-model="form.sortOrder" style="width:600px"/>
                            </FormItem>
                            <FormItem label="状态" prop="isShow" >
                                <RadioGroup v-model="form.isShow" >
                                    <Radio :label="1" >展示</Radio>
                                    <Radio :label="2" >隐藏</Radio>
                                </RadioGroup>
                            </FormItem>
                            <Form-item class="br" v-if="!disabledSingle">
                                <Button type="primary" :loading="submitLoading" @click="handelSubmit" style="width:80px">提交</Button>
                                <Button @click="handelCancel">取消</Button>
                            </Form-item>
                            <Spin size="large" fix v-if="loading"></Spin>
                        </Form>
                    </Row>
                </Card>
                </Col>
            </Row>
        </Drawer>
    </div>
</template>
<script>
    import {indexAddOrEdit} from "@/api/bus";
    import uploadInput from "@/views/my-components/flyme/upload-input";
    // 表情包配置 自定义表情可在该js文件中统一修改
    import {sina} from "@/libs/emoji";
    export default {
        name: "activity-drawer",
        components: {
            uploadInput
        },
        data() {
            return {
                disabledSingle: false,
                readonly: true,
                picVisible: false,
                fileUrl: "",
                loading: false, // 表单加载状态
                drawerTitle: "编辑首页模块",
                drawerVisible: false,
                form: {},
                submitLoading: false, // 添加或编辑提交状态
                formValidate: {
                    tagName: [{required: true, message: "模块名称不能为空", trigger: "blur"}],
                    sortOrder: [{required: true,type: 'number', message: "排序不能为空", trigger: "blur"}],
                }
            };
        },
        methods: {
            showDrawer(params) {
                if(params){
                    this.drawerTitle = "编辑首页模块"
                    this.form.id = params.id
                    this.form.tagName = params.tagName
                    this.form.isShow = params.isShow
                    this.form.sortOrder = params.sortOrder
                }else{
                    this.drawerTitle = "新增首页模块"
                    this.cleanForm()
                }
                this.drawerVisible = true;
            },
            cleanForm(){
                this.form.id = ''
                this.form.tagName = ''
                this.form.isShow = 1
                this.form.sortOrder = 0
            },
            handelSubmit() {
                this.$refs.form.validate(valid => {
                    if (valid) {
                        this.submitLoading = true;
                        // 编辑
                        indexAddOrEdit(this.form).then(res => {
                            this.submitLoading = false;
                            if (res.status === true) {
                                this.$Message.success("操作成功");
                                this.$parent.getDataList();
                                this.drawerVisible = false;
                            }
                        });
                    }
                });
            },
            showPic(v) {
                this.fileUrl = v;
                this.picVisible = true;
            },
            handelCancel() {
                this.drawerVisible = false;
            }
        },
        mounted() {

        },
        watch: {

        }
    };
</script>